package com.tmall.qatest.info;

import com.taobao.dpservice.base.BaseDO;
import com.taobao.dpservice.constant.NotifyMessageTypeEnum;
import com.taobao.hsf.notify.client.message.Message;
import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang.math.NumberUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: Shuffle
 * Date: 13-2-5
 * Time: 下午4:19
 * To change this template use File | Settings | File Templates.
 */
public class DpcMessageInfo extends BaseDO {
    private long time = System.currentTimeMillis();

    private boolean isOnceMessage;

    private int messageType;

    private NotifyMessageTypeEnum typeEnum;

    private Message message;

    private Map<String, Object> content = new HashMap<String, Object>();

    /**
     * �ӳ�Ͷ��ʱ�䣬��λ����
     */
    private Long postDelayTime;

    public DpcMessageInfo() {
    }

    public DpcMessageInfo(NotifyMessageTypeEnum typeEnum) {
        super();
        this.typeEnum = typeEnum;
        this.messageType = typeEnum.getType();
    }

    public long getLong(String key) {
        return NumberUtils.toLong(getString(key), 0);
    }

    public int getInt(String key) {
        return NumberUtils.toInt(getString(key), 0);
    }

    public String getString(String key) {
        return String.valueOf(content.get(key));
    }

    public Boolean getBoolean(String key) {
        return BooleanUtils.toBoolean(getString(key));
    }

    @SuppressWarnings("unchecked")
    public List<Long> getListLong(String key) {
        return (List<Long>) content.get(key);
    }

    @SuppressWarnings("unchecked")
    public Map<Long, String> getMap(String key) {
        return (Map<Long, String>) content.get(key);
    }

    @SuppressWarnings("unchecked")
    public List<String> getListString(String key) {
        return (List<String>) content.get(key);
    }

    @SuppressWarnings("unchecked")
    public List<Integer> getListInteger(String key) {
        return (List<Integer>) content.get(key);
    }

    public Object addValue(String key, Object value) {
        if (value == null) {
            return null;
        }
        return content.put(key, value);
    }

    public Long getTime() {
        return time;
    }

    public void setTime(Long time) {
        this.time = time;
    }

    public int getMessageType() {
        return messageType;
    }

    public void setMessageType(int messageType) {
        this.messageType = messageType;
    }

    public Map<String, Object> getContent() {
        return content;
    }

    public void setContent(Map<String, Object> content) {
        this.content = content;
    }

    public Message getMessage() {
        return message;
    }

    public void setMessage(Message message) {
        this.message = message;
    }

    public boolean isOnceMessage() {
        return isOnceMessage;
    }

    public void setOnceMessage(boolean isOnceMessage) {
        this.isOnceMessage = isOnceMessage;
    }

    public Long getPostDelayTime() {
        return postDelayTime;
    }

    public void setPostDelayTime(Long postDelayTime) {
        this.postDelayTime = postDelayTime;
    }

    public NotifyMessageTypeEnum getTypeEnum() {
        return typeEnum;
    }

    public void setTypeEnum(NotifyMessageTypeEnum typeEnum) {
        this.typeEnum = typeEnum;
        this.messageType = typeEnum.getType();
    }
}
